package com.sx.basic;

import com.sx.basic.pageable.Condition;
import com.sx.basic.pageable.PageRequest;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * @author AdinZ
 * @date 2020/11/10 14:30
 */
public interface IBasicService<T extends BasicEntity,ID extends Serializable>{
    T get(ID id);

    void delete(ID... ids);
    void delete(Condition condition);

    T update(T t);

    void update(List<T> list);

    boolean save(T t);

    void save(List<T> list);


    List<T> findList(Condition condition);

    List<T> listById(Collection<ID> collection);



    /**
     * 单纯的分页查询
     * @param page 页码
     * @param size 页数
     * @return
     */
    ResponseEntity<List<T>> findPage(int page,int size);

    /**
     * 还是个单纯的分页查询
     * @param pageable 此对象可以包含 页码页数, 排序
     * @return
     */
    ResponseEntity<List<T>> findPage(PageRequest pageable);

    /**
     * 分页查询, 多个条件语句
     * @param condition 条件map
     * @param pageable
     * @return
     */
    ResponseEntity<List<T>> findPage(Condition condition, PageRequest pageable);


    default  <E>ResponseEntity<E> toSuccess(String message,E data){
        return new ResponseEntity().toSuccess(message,data);
    }
    default ResponseEntity toError(int code,String message){
        return new ResponseEntity(code,message);
    }
    default ResponseEntity toError(String message){
        return toError(300,message);
    }
    default ResponseEntity toError(){
        return toError("参数错误");
    }
    default <E>ResponseEntity<E> toSuccess(E data){
        return toSuccess("",data);
    }
    default ResponseEntity toSuccess(){
        return toSuccess(null);
    }



}
